import React, { useEffect, useState } from "react";
import Item from "./item";
import pubsub from "pubsub-js";
export default function List() {
  const [addList, setAddList] = useState({
    isInit: true,
    isSearch: false,
    data: [],
  });
  useEffect(() => {
    pubsub.subscribe("github", (_, data) => {
      setAddList(data);
    });
  }, []);
  return (
    <div>
      <div className="row">
        {addList.isInit ? (
          <h2>请开始搜索</h2>
        ) : addList.isSearch ? (
          <h2>正在搜索中....</h2>
        ) : (
          addList.data.map((item) => {
            return <Item key={item.id} {...item} />;
          })
        )}
      </div>
    </div>
  );
}
